package com.manyauthenticationway.server.manyauthenticationway.domain.user

import com.alibaba.fastjson.JSONObject
import org.apache.commons.logging.LogFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.web.bind.annotation.*
import java.security.Principal

@RestController
@RequestMapping("/sysUser")
class SysUserController {
    private val logger=LogFactory.getLog(SysUserController::class.java)
    @Autowired
    lateinit var sysUserService: SysUserService;

    @PostMapping("/insert")
    fun insert(@RequestBody sysUser: SysUser) = sysUserService.insert(sysUser)

    @DeleteMapping("/delete")
    fun delete(@RequestBody sysUser: SysUser) = sysUserService.delete(sysUser)

    @PutMapping("/update")
    fun update(@RequestBody sysUser: SysUser) = sysUserService.update(sysUser)

    @GetMapping("/queryByMany")
    fun queryByPage(
            @RequestParam params: Map<String,Any>,
            @RequestParam(required = false, defaultValue = "0") page: Int,
            @RequestParam(required = false, defaultValue = "10") size: Int,
            @RequestParam(required = false, defaultValue = "DESC") dir: Sort.Direction,
            @RequestParam(required = false, defaultValue = "id") sort: String
    ) = sysUserService.queryByPage(params,PageRequest.of(page,size,dir,sort))

    @GetMapping("/queryByOne")
    fun selectByOne(@RequestParam params: Map<String,Any>,principal: Principal): JSONObject{
        return sysUserService.selectByOne(params,principal)
    }
}